<?php
/**
 * Created by PhpStorm.
 * User: 69548
 * Date: 2018/7/25
 * Time: 10:42
 */

namespace app\api\controller;

use app\api\controller\Boos;
use  app\api\model\Classify as M;
class Classify extends Base
{

    //导航数据


    public function index(){

        $m=new M();
      $data=  $m->classify();


      return json_encode($data);
    }

    public function classifypoi(){


        $m=new M();
        $id=input('classify_id');
        $lat=input('lat');
        $lng=input('lng');
       $score_sort1= input('score_sort');
       $distance_sort1= input('distance_sort');
        $score_sort=!empty($score_sort1)?$score_sort1:'1';//默认为1
        $distance_sort=!empty($distance_sort1)?$distance_sort1:'1';//默认为1
        $data=   $m->classifypoi($id,$lat,$lng);

        if ($score_sort!="1"){
           $data= $this->sort($data,'score','>');
        }
        if ($distance_sort!="1"){

            $data= $this->sort($data,'juli','<');
        }



     return json_encode($data);
    }

    public  function sort($a,$c,$f){
        $len= count($a);
        for($k=0;$k<=$len;$k++)
        {
            for($j=$len-1;$j>$k;$j--){
                if($a[$j][$c].$f.$a[$j-1][$c]){
                    $temp = $a[$j];
                    $a[$j] = $a[$j-1];
                    $a[$j-1] = $temp;
                }
            }
        }

        return $a;
    }


}